package com.gwall.zk.composers;

import io.keikai.api.Range;
import io.keikai.api.Ranges;
import io.keikai.api.model.Book;
import io.keikai.api.model.CellData;
import io.keikai.ui.event.CellMouseEvent;
import lombok.extern.slf4j.Slf4j;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;

@Slf4j
public class MyComposer extends SelectorComposer<Component> {

    @Listen("onCellClick = #ss")
    public void onCellClick(CellMouseEvent event){
        int row = event.getRow();
        int col = event.getColumn();
        log.info("row = {}, col = {}", row, col);
        StringBuilder info = new StringBuilder();
        info.append("Click on cell ")
                .append(Ranges.getCellRefString(row,col));
        log.info("onCellClick, {}", info);
        //show event information...

        Range range = Ranges.range(event.getSheet(),row,col);
        CellData cellData = range.getCellData();

        log.info("cellData.getStringValue() = {}", cellData.getStringValue());

        cellData.setEditText("Hello World");

    }
    @Listen("onCellRightClick = #ss")
    public void onCellRightClick(CellMouseEvent event){
        //show event information...
        log.info("onCellRightClick");
    }
    @Listen("onCellDoubleClick = #ss")
    public void onCellDoubleClick(CellMouseEvent event){
        //show event information...
        log.info("onCellDoubleClick");
    }

}
